1 '                 STUDENT'S T-TEST (two-tailed)
2 '               Written by Tracy L. Gustafson, M.D.
3 '              Round Rock, Texas. Version 3.0, 1984
4 ON ERROR GOTO 5000:CHAIN MERGE "EPIMRG",5
15 DIM D(1),CS(1),T(1),N$(1),X(1),X2(1),MD(1),SD(1)
22 DATA "STUDENT'S T-TEST (two-tailed)",21,31
30 LOCATE 6,7:PRINT "(Press RETURN if you wish to skip directly to T evaluation)"
35 LOCATE 5,1:GOSUB 4000
40 PRINT:PRINT:PRINT TAB(4);"What are the SAMPLE NUMBERS of the 2 variables you want to compare?":PRINT TAB(10);:AR=CSRLIN
45 AC=17:GOSUB 4200:NS1=NS:AC=47:GOSUB 4200:NS2=NS
50 PRINT TAB(5);"Means =";TAB(19);X(NS1)/T(NS1);TAB(49);X(NS2)/T(NS2)
55 PRINT "Variances =";TAB(19);SD(NS1)^2;TAB(49);SD(NS2)^2:PRINT
60 PRINT TAB(10);"Are these INDEPENDENT or PAIRED samples? (I or P)   ";
65 INPUT"", A$:IF A$="I" OR A$="i" THEN 90 ELSE IF A$<>"P" AND A$<>"p" THEN BEEP:GOTO 60
70 IF T(NS1)<>T(NS2) THEN BEEP:PRINT:PRINT "These 2 samples do not have the same number of elements---":PRINT TAB(37);"a paired T-TEST cannot be performed.":GOTO 220
75 XD=0:XD2=0:N=T(NS1):V=N-1
80 FOR Z=1 TO N:ED=VAL(D(NS1,Z))-VAL(D(NS2,Z)):XD=XD+ED:XD2=XD2+ED*ED:NEXT
85 VD=(XD2-XD*XD/N)/V:ST=ABS(XD/N)*SQR(N)/SQR(VD):GOTO 115
90 N1=T(NS1):N2=T(NS2):V=N1+N2-2:V1=N1-1:V2=N2-1
95 VR=((X2(NS1)-X(NS1)*X(NS1)/N1)+(X2(NS2)-X(NS2)*X(NS2)/N2))/V
100 VR=VR*(1/N1+1/N2):ST=ABS(X(NS1)/N1-X(NS2)/N2)/SQR(VR)
105 F=SD(NS1)^2/SD(NS2)^2:IF F<1 THEN F=1/F:SWAP V1,V2
110 GOSUB 240:IF P<.05 THEN PRINT:PRINT "The T-TEST may not be appropriate because these variances":PRINT TAB(20);"are so different (F =";F;"  p ";:IF P<.000001 THEN PRINT "< 10 (-6) )." ELSE PRINT "=";P;")."
115 PRINT:PRINT TAB(12);"T = ";ST;TAB(53);"df = ";V:GOTO 135
120 CLS:PRINT TAB(17);"EVALUATING THE T DISTRIBUTION  (two-tailed)":PRINT TAB(17);STRING$(43,205)
125 LOCATE 8,11:INPUT;"Enter T value:  ",ST:ST=ABS(ST)
130 PRINT TAB(43);:INPUT "degrees of freedom:  ",V:PRINT
135 R=ATN(ST/SQR(V)):RC=COS(R):R2=RC*RC:RS=SIN(R):X=1
140 IF V MOD 2=0 THEN 165
145 IF V=1 THEN Y=R:GOTO 160
150 Y=RC:FOR Z=3 TO (V-2) STEP 2:X=X*R2*(Z-1)/Z:Y=Y+X*RC:NEXT
155 Y=R+RS*Y
160 P=1-Y*.6366197723657157#:GOTO 175
165 Y=1:FOR Z=2 TO (V-2) STEP 2:X=X*R2*(Z-1)/Z:Y=Y+X:NEXT
170 P=1-Y*RS
175 PLAY "MB O3 L32 MS DF#A O4 DF#A O5 L8 D"
180 PRINT TAB(26);:COLOR CLR2,CLR1:PRINT "     p = ";:IF P<.000001 THEN PRINT"< 10 (-6)"; ELSE PRINT P;
185 PRINT TAB(50):IF AF=1 THEN COLOR CLR1,CLR2:GOTO 230
190 PRINT TAB(8);"The MEANS of these 2 samples are ";:IF P>.05 THEN PRINT "NOT ";
195 PRINT "significantly different.";TAB(75):COLOR CLR1,CLR2
200 PRINT:PRINT:PRINT "The confidence limits on the DIFFERENCE between the means of these samples":PRINT "can be calculated as: ":PRINT TAB(25);
205 DF=STR$(V):DF=RIGHT$(DF,LEN(DF)-1):IF A$="i" OR A$="I" THEN 215
210 YD=ABS(XD/N):PRINT YD; "+/- T(";DF;") * ";SQR(VD/N):GOTO 220
215 YD=ABS(X(NS1)/N1-X(NS2)/N2):PRINT YD;"+/- T(";DF;") * ";SQR(V1)
220 DQ="Do you want another T-TEST using ":LOCATE 25,15:PRINT DQ;:INPUT;"this datafile?   ",A$:IF A$="y" OR A$="Y" THEN CLS:GOTO 40
225 LOCATE 25,12:PRINT DQ;:INPUT;"a DIFFERENT datafile?  ",A$:IF A$="y" OR A$="Y" THEN 20 ELSE 235
230 LOCATE 25,17:INPUT;"Do you want to evaluate another T value?  ",A$:IF A$="y" OR A$="Y" THEN 120
235 LOCATE 23,1:END
240 X=1/(V1/V2*F+1):Y=1-X:PF=1:PT=1:VA=V1:VB=V2
245 IF V1 MOD 2<>0 THEN IF V2 MOD 2=0 THEN 265 ELSE 275
250 IF V2 MOD 2=0 THEN IF V2>=V1 THEN 265
255 FOR Z=1 TO (V1/2-1):PF=PF*(.5/Z*Y*VB):PT=PT+PF:VB=VB+2:NEXT
260 P=X^(V2*.5)*PT:GOTO 325
265 FOR Z=1 TO (V2/2-1):PF=PF*(.5/Z*X*VA):PT=PT+PF:VA=VA+2:NEXT
270 P=1-Y^(V1*.5)*PT:GOTO 325
275 XT=ATN(SQR(F*V1/V2)):X=SIN(XT):Y=COS(XT):PT=Y:PF=Y
280 IF V2=1 THEN 295
285 FOR Z=2 TO (V2-3) STEP 2:PF=PF*Y*Y*Z/(Z+1):PT=PT+PF:NEXT
290 PT=PT*X:XT=XT+PT
295 PT=1:PF=1:IF V1=1 THEN 320
300 FOR Z=2 TO (V2-1) STEP 2:PF=PF*Z/(Z-1):NEXT
305 PF=PF*Y^V2*X:PZ=1:PT=1:VB=V2+1
310 FOR Z=3 TO (V1-2) STEP 2:PZ=PZ*VB*X*X/Z:PT=PT+PZ:VB=VB+2:NEXT
315 XT=XT-PT*PF
320 P=1-XT*2/3.141592653599#
325 RETURN
4010 AF=0:IF FILE$="" THEN AF=1:GOTO 120
4025 ERASE D,CS,T,N$,X,X2,MD,SD
4030 DIM D(A,C),CS(A,C),T(A),N$(A),X(A),X2(A),MD(A),SD(A)
5000 BEEP:IF ERR<>53 AND ERR<>71 THEN 5010 ELSE LOCATE 10,10:PRINT "Please place EPISTAT in drive A: (or other default).":PRINT TAB(25);"Press any key to continue:"
5005 A$=INKEY$:IF A$="" THEN 5005 ELSE RESUME
5010 ON ERROR GOTO 0:END
